package edu.online.dal;

import edu.online.entity.UserEntity;
import org.apache.ibatis.jdbc.SQL;

public class UserEntitySqlProvider {

    public String insertSelective(UserEntity record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("tuser");
        
        if (record.getUserid() != null) {
            sql.VALUES("UserId", "#{userid,jdbcType=CHAR}");
        }
        
        if (record.getUsername() != null) {
            sql.VALUES("UserName", "#{username,jdbcType=VARCHAR}");
        }
        
        if (record.getPasswd() != null) {
            sql.VALUES("Passwd", "#{passwd,jdbcType=VARCHAR}");
        }
        
        if (record.getEmail() != null) {
            sql.VALUES("Email", "#{email,jdbcType=VARCHAR}");
        }
        
        if (record.getMobile() != null) {
            sql.VALUES("Mobile", "#{mobile,jdbcType=CHAR}");
        }
        
        if (record.getRole() != null) {
            sql.VALUES("Role", "#{role,jdbcType=VARCHAR}");
        }
        
        return sql.toString();
    }

    public String updateByPrimaryKeySelective(UserEntity record) {
        SQL sql = new SQL();
        sql.UPDATE("tuser");
        
        if (record.getUsername() != null) {
            sql.SET("UserName = #{username,jdbcType=VARCHAR}");
        }
        
        if (record.getPasswd() != null) {
            sql.SET("Passwd = #{passwd,jdbcType=VARCHAR}");
        }
        
        if (record.getEmail() != null) {
            sql.SET("Email = #{email,jdbcType=VARCHAR}");
        }
        
        if (record.getMobile() != null) {
            sql.SET("Mobile = #{mobile,jdbcType=CHAR}");
        }
        
        if (record.getRole() != null) {
            sql.SET("Role = #{role,jdbcType=VARCHAR}");
        }
        
        sql.WHERE("UserId = #{userid,jdbcType=CHAR}");
        
        return sql.toString();
    }
}